package com.wwz.controller;

import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.core.date.DateTime;
import com.wwz.pojo.Admin;
import com.wwz.pojo.model.LoginModel;
import com.wwz.service.IAdminService;
import com.wwz.util.JobUtils;
import com.wwz.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 管理员控制层
 * @date 2022/02/18 27:11:38
 */
@RestController
@RequestMapping("/centre/admin")
@Api(tags = "管理员控制层")
public class AdminController {

    @Resource
    private IAdminService adminService;

    @ApiOperation("admin登录")
    @PostMapping("/login")
    public Result login(@RequestBody LoginModel loginModel){
        //登录效验
        JobUtils.checkLoginModel(loginModel);

        LoginModel login = adminService.login(loginModel);

        if (login!=null){
            return Result.ok("ok",login);
        }
        return Result.error("用户名密码错误!");
    }

    @ApiOperation("获取验证码")
    @GetMapping("/getImg")
    public void getImg(HttpServletResponse response){
        JobUtils.createImaCode(response);
    }

    @ApiOperation("退出登陆")
    @PostMapping("/outLogin")
    public Result outLogin(){
        StpUtil.logout();
        return Result.ok("退出登陆！");
    }

    @ApiOperation("是否登录")
    @PostMapping("/isLogin")
    public Result isLogin( ){
        StpUtil.checkLogin();
        return Result.ok();
    }
}
